
// 功能: 向文件中写入字符(write file1)
void write()
{
int i, inum, length;
if(argc != 2)
{
printf("Command write must have one args. \n");
return ;
}
for(i = 0; i < FILENUM; i++)
if((file_array[i].inum>0)&&
!strcmp(file_array[i].file_name,argv[1])) break;
if(i == FILENUM)
{
printf("Open %s first.\n", argv[1]);
return ;
}
else if(file_array[i].mode == 1)
{
printf("Can't write %s.\n", argv[1]);
return ;
}
inum = file_array[i].inum;
printf("The length of %s:%d\n", inode_array[inum].file_name, inode_array[inum].length);
if(inode_array[inum].length == 0)
{
printf("The length you want to write(0-1024):");
scanf("%d", &length);
gets(temp);
if((length < 0) && (length >1024))
{
printf("Input wrong.\n");
return ;
}
inode_array[inum].length = length;
inode_array[inum].address[0] = get_blknum();
if(length > 512)
inode_array[inum].address[1] = get_blknum();
save_inode(inum);
printf("Input the data(Enter to end):\n");
gets(temp);
write_blk(inum);
}
else
printf("This file can't be written.\n");
}
// 功能: 关闭已经打开的文件(close file1)
void close(void)
{
int i;
if(argc != 2)
{
printf("Command close must have one args. \n");
return ;
}
for(i = 0; i < FILENUM; i++)
if((file_array[i].inum > 0) &&
!strcmp(file_array[i].file_name, argv[1])) break;
if(i == FILENUM)
{
printf("This file doesn't be opened.\n");
return ;
}
else
{
file_array[i].inum = -1;
printf("Close %s successful!\n", argv[1]);
}
}
//删除目录树
void delet(int innum)
{
/*int chk;
chk=check(innum);
if(chk!=1)
{
//printf("This directory is not yours !\n");
return ;
  }*/
inode_array[innum].inum = -1;
if(inode_array[innum].length >= 0)
{
  release_blk(inode_array[innum].address[0]);
  if(inode_array[innum].length >= 512)
release_blk(inode_array[innum].address[1]);
}
save_inode(innum);
}